<?php
// 主要是用来网站静态化
class Default_HtmlController extends Cff_Controller_Action {
	public function preDispatch() {
		$this->domain = 'http://' . $_SERVER ['SERVER_NAME'];
	}
	public function indexAction() {
		$count = Lucene_Service_History::getByCondition ( array (), "count(*)" );
		$this->view->count = $count;
		echo $this->view->render ( "html.phtml" ); // 视图文件为完整网页 不使用layout
	}
	public function batchToHtmlAction() {
		$page = $this->getRequest ()->getParam ( "page", 0 );
		$pageSize = $this->getRequest ()->getParam ( "pageSize", 20 );
		$page = empty ( $page ) ? 1 : $page;
		
		$list = Lucene_Service_History::getByCondition ( array (), "*", array (), $pageSize, $page );
		$json = array (
				"status" => 0 
		);
		$arr = array ();
		try {
			if (count ( $list ) > 0) {
				foreach ( $list as $v ) {
					$id = $v ['houseid'];
					if (empty ( $id )) {
						throw new Exception ( "id empty" );
					}
					$html = $this->view->render ( "html_template.phtml" ); // 视图文件为完整网页
					                                                     // 不使用layout.
					$filePath = Default_Service_Html::getdir ( $id,"house", true );
					$fileName = "$id.html";
					file_put_contents ( $filePath ['abPath'] . "/" . $fileName, $html );
					$arr [] = $filePath ['path'] . "/" . $fileName;
				}
				$json ['status'] = 1;
			}
		} catch ( Exception $e ) {
			$json ['msg'] = $e->getMessage ();
		}
		$json ['data'] = $arr;
		echo Zend_Json::encode ( $json );
	}
}